<template>
  <div class="app-container">
    <el-dialog title="积分兑换" :visible.sync="dialogconUp" center @close="close">
      {{ accuseitem }}
      <el-form :model="accuseitem" :rules="rules" ref="accuseitem" label-width="120px" class="demo-presentlist">
        <el-form-item label="商品名称" prop="cname">
          <el-input disabled v-model="accuseitem.cname" style="width: 450px"></el-input>
        </el-form-item>
        <el-form-item label="用户电话号码" prop="money">
          <el-input v-model="accuseitem.phone" style="width: 450px"></el-input>
        </el-form-item>
        <el-form-item style="margin-top: 20px">
          <el-button type="primary" @click="submitForm('accuseitem')">修改</el-button>
          <el-button @click="resetForm('accuseitem')">重置</el-button>
        </el-form-item>
      </el-form>
      {{ presentlist }}
    </el-dialog>

  </div>
</template>
<script>
import integral from "@/api/integral";

export default {
  props: {
    dialogconUpdate: {
      type: Boolean,
      default: false
    },
    accuseitem: {}
  },
  data() {
    return {
      dialogconUp: false,
      dialogImageUrl: '',
      presentlist: {
        cid: '',//商品名称
        phone: '',//商品积分价格
      },
      rules: {
        money: [
          {required: true, message: '请输入电话号码', trigger: 'blur'},
        ],
      }
    };
  },
  methods: {
    close() {
      this.$emit("update:dialogconUpdate", false)
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        this.presentlist.cid = this.accuseitem.id;
        this.presentlist.phone = this.accuseitem.phone;
        console.log(this.presentlist)
        integral.findPointsExchange(this.presentlist)
            .then(res => {
              console.log(res)
              if (res.data == true) {
                this.$message({
                  type: 'success',
                  message: '兑换成功!',
                });
                this.close();
              } else {
                this.$message({
                  type: 'defeated',
                  message: '兑换失败!',
                });
              }
            })
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  watch: {
    dialogconUpdate: {
      handler(newValue, oldValue) {
        this.dialogconUp = newValue;
        console.log(newValue, oldValue);
      }
    }
  }
}
</script>
